#!/usr/bin/env python
# -*- coding=utf-8 -*-
from tornado import web as tor_web
from tornado import ioloop
from tornado import httpserver
from tornado import options

options.define("port", default=8000, type=int, help="run server on the given port.") # 定义服务器监听端口选项
options.define("itcast", default=[], type=str, multiple=True, help="itcast subjects.") # 无意义，演示多值情况

class IndexHandler(tor_web.RequestHandler):
    """
    IndexHandler
    """

    def get(self):
        self.write("hello tornado!")


if __name__ == '__main__':
    
    # options.parse_command_line() 解析命令行，
    # 将命令行中的参数传入到全局变量tornado.options.options中对应的变量中

    #加载配置文件,配置文件传多个值时，需要注意格式：值要设置为
    options.parse_config_file("./config.ini")
    options.logging = None
    
    print(options.options.itcast)
    app = tor_web.Application([
        (r"^/$", IndexHandler),
    ])

    http_server = httpserver.HTTPServer(app)
    print(options.options.port)
    http_server.listen(options.options.port)

    ioloop.IOLoop.current().start()
